//
//  TT_Alert.m
//  ZKGX
//
//  Created by 王洋 on 2020/3/20.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "TT_Alert.h"
#import "SCLAlertView.h"

@implementation TT_Alert

//+ (void)alert:(NSString *)message {
//    
//    SCLAlertView *alert = [[SCLAlertView alloc] initWithNewWindowWidth:TTScreenWidth - 60];
//    alert.showAnimationType = SCLAlertViewShowAnimationSlideInToCenter;
//    [alert showTitle:@"提示" subTitle:message style:SCLAlertViewStyleNotice closeButtonTitle:@"确认" duration:0.0];
//}

+ (void)alert:(NSString *)message title:(NSString *)title doneTitle:(NSString *)doneTitle doneAction:(void (^)(void))doneAction {
    
    SCLAlertView *alert = [[SCLAlertView alloc] initWithNewWindowWidth:TTScreenWidth - 70];
    alert.showAnimationType = SCLAlertViewShowAnimationSlideInToCenter;
    [alert removeTopCircle];//去掉头部圆圈
    alert.cornerRadius = 8.0f;
        
    SCLButton *doneButton = [alert addButton:doneTitle actionBlock:^{
        doneAction();
    }];

    [doneButton setBackgroundImage:[UIImage imageNamed:@"rect_orange"] forState:UIControlStateNormal];
    
    doneButton.buttonFormatBlock = ^NSDictionary *{
        NSMutableDictionary *buttonConfig = [[NSMutableDictionary alloc] init];
        buttonConfig[@"backgroundColor"] = UIColorHex(0xff4242);
        buttonConfig[@"textColor"] = [UIColor whiteColor];

        return buttonConfig;
    };
    
    [alert showTitle:title subTitle:message style:SCLAlertViewStyleNotice closeButtonTitle:nil duration:0.0];
    
    alert.labelTitle.font = [UIFont systemFontOfSize:16 weight:UIFontWeightSemibold];
    alert.labelTitle.textColor = UIColorHex(0x222222);
    
    alert.viewText.font = [UIFont systemFontOfSize:14];
    alert.viewText.textColor = UIColorHex(0x666666);
}

+ (void)alert:(NSString *)message doneAction:(void (^)(void))doneAction {
    
    SCLAlertView *alert = [[SCLAlertView alloc] initWithNewWindowWidth:TTScreenWidth - 60];
    alert.showAnimationType = SCLAlertViewShowAnimationSlideInToCenter;
    [alert removeTopCircle];//去掉头部圆圈
    alert.cornerRadius = 8.0f;
    
    SCLButton *doneButton = [alert addButton:@"确定" actionBlock:^{
        doneAction();
    }];
    [doneButton setBackgroundImage:[UIImage imageNamed:@"rect_orange"] forState:UIControlStateNormal];

    doneButton.buttonFormatBlock = ^NSDictionary *{
        NSMutableDictionary *buttonConfig = [[NSMutableDictionary alloc] init];
        buttonConfig[@"backgroundColor"] = UIColorHex(0xff4242);
        buttonConfig[@"textColor"] = [UIColor whiteColor];

        return buttonConfig;
    };
    
    [alert showTitle:@"提示" subTitle:message style:SCLAlertViewStyleNotice closeButtonTitle:nil duration:0.0];
    alert.labelTitle.font = [UIFont systemFontOfSize:16 weight:UIFontWeightSemibold];
    alert.labelTitle.textColor = UIColorHex(0x222222);
    
    alert.viewText.font = [UIFont systemFontOfSize:14];
    alert.viewText.textColor = UIColorHex(0x666666);
}

+ (void)alert:(NSString *)message cancleBtnTitle:(NSString *)cancleTitle cancleAction:(void (^)(void))cancleAction doneBtnTitle:(NSString *)doneTitle doneAction:(void (^)(void))doneAction {
    
    SCLAlertView *alert = [[SCLAlertView alloc] initWithNewWindowWidth:TTScreenWidth - 60];
    alert.showAnimationType = SCLAlertViewShowAnimationSlideInToCenter;
    [alert removeTopCircle];//去掉头部圆圈
    alert.cornerRadius = 8.0f;
    
    [alert setHorizontalButtons:YES];
    
    SCLButton *cancleButton = [alert addButton:cancleTitle actionBlock:^{
        cancleAction();
    }];
    
    cancleButton.buttonFormatBlock = ^NSDictionary *{
        NSMutableDictionary *buttonConfig = [[NSMutableDictionary alloc] init];
        buttonConfig[@"backgroundColor"] = [UIColor whiteColor];
        buttonConfig[@"textColor"] = UIColorHex(0xff5539);
        buttonConfig[@"borderWidth"] = @1.0f;
        buttonConfig[@"borderColor"] = UIColorHex(0xff5539);
        return buttonConfig;
    };
    
    SCLButton *doneButton = [alert addButton:doneTitle actionBlock:^{
        doneAction();
    }];

    doneButton.buttonFormatBlock = ^NSDictionary *{
        NSMutableDictionary *buttonConfig = [[NSMutableDictionary alloc] init];
        buttonConfig[@"backgroundColor"] = UIColorHex(0xFF5539);
        buttonConfig[@"textColor"] = [UIColor whiteColor];
        return buttonConfig;
    };
    
    [alert showTitle:@"提示" subTitle:message style:SCLAlertViewStyleNotice closeButtonTitle:nil duration:0.0];
    alert.labelTitle.font = [UIFont systemFontOfSize:16 weight:UIFontWeightSemibold];
    alert.labelTitle.textColor = UIColorHex(0x222222);
    
    alert.viewText.font = [UIFont systemFontOfSize:14];
    alert.viewText.textColor = UIColorHex(0x666666);
}

+ (void)alertTitle:(NSString *)title message:(NSString *)message leftBtnTitle:(NSString *)leftTitle leftAction:(void (^)(void))leftAction rightBtnTitle:(NSString *)rightTitle rightAction:(void (^)(void))rightAction cancleAction:(void (^)(void))cancleAction {
    
    SCLAlertView *alert = [[SCLAlertView alloc] initWithNewWindowWidth:TTScreenWidth - 60];
    alert.showAnimationType = SCLAlertViewShowAnimationSlideInToCenter;
    [alert removeTopCircle];//去掉头部圆圈
    alert.cornerRadius = 8.0f;
    
    [alert setHorizontalButtons:YES];
    
    UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [closeBtn setImage:[UIImage imageNamed:@"close_gray"] forState:UIControlStateNormal];
    closeBtn.frame = CGRectMake(TTScreenWidth - 100, 0, 40, 40);
    [closeBtn addGestureTapEventHandle:^(id  _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) {
        if ([alert isVisible]) {
            [alert hideView];
        }
        cancleAction();
    }];
    
    [alert.view addSubview:closeBtn];
    
    SCLButton *leftButton = [alert addButton:leftTitle actionBlock:^{
        leftAction();
    }];
    
    leftButton.buttonFormatBlock = ^NSDictionary *{
        NSMutableDictionary *buttonConfig = [[NSMutableDictionary alloc] init];
        buttonConfig[@"backgroundColor"] = [UIColor whiteColor];
        buttonConfig[@"textColor"] = UIColorHex(0xff5539);
        buttonConfig[@"borderWidth"] = @1.0f;
        buttonConfig[@"borderColor"] = UIColorHex(0xff5539);
        return buttonConfig;
    };
    
    SCLButton *rightButton = [alert addButton:rightTitle actionBlock:^{
        rightAction();
    }];

    rightButton.buttonFormatBlock = ^NSDictionary *{
        NSMutableDictionary *buttonConfig = [[NSMutableDictionary alloc] init];
        buttonConfig[@"backgroundColor"] = UIColorHex(0xFF5539);
        buttonConfig[@"textColor"] = [UIColor whiteColor];
        return buttonConfig;
    };
    
    [alert showTitle:title subTitle:message style:SCLAlertViewStyleNotice closeButtonTitle:nil duration:0.0];
    alert.labelTitle.font = [UIFont systemFontOfSize:16 weight:UIFontWeightSemibold];
    alert.labelTitle.textColor = UIColorHex(0x222222);
    
    alert.viewText.font = [UIFont systemFontOfSize:14];
    alert.viewText.textColor = UIColorHex(0x666666);
}

@end
